package org.example.zsfmybatis.service;

import org.example.zsfmybatis.mapper.MealsMapper;
import org.example.zsfmybatis.model.Meals;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MealsService {
    @Autowired
    MealsMapper mealsMapper;
    public double pricesum(String id,int sum){
        Meals meals = mealsMapper.getMealsById(id);
        if(meals.getSum()>=sum){
            meals.setSum(meals.getSum()-sum);
            mealsMapper.updateMealsById(id,sum);
            return meals.getSum()*meals.getPrice();
        }
        else return -1.0;
    }
    public Meals findbyid(String id){
        return mealsMapper.getMealsById(id);
    }

}
